<?php

declare(strict_types=1);

namespace app\admin\validate;

use think\Validate;

class SystemLanguage extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id'            => 'integer|gt:0',
        'chinese_name' => 'require|regex:/^[\x{4e00}-\x{9fa5}]+$/u|length:1,256',
        'english_name' => 'require|regex:/^[a-zA-Z]+$/u|length:1,256',
        'name' => 'regex:/^[\p{L}\p{Zs}]+$/u|length:1,256',
        'status' => 'in:0,1'
    ];


    protected $scene = [
        'save' => ['id', 'chinese_name', 'english_name'],
        'search' => ['name'],
        'status' => ['status'],
    ];
    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.integer'            => 'ID 必须是整数',
        'id.gt'                 => 'ID 必须大于0',
        'chinese_name.require'  => '中文名称为必填项',
        'chinese_name.regex'    => '中文名称只能包含中文',
        'chinese_name.length'   => '中文名称长度超出256个字符',
        'english_name.require'  => '英文名称为必填项',
        'english_name.regex'    => '英文名称只能包含英文',
        'english_name.length'   => '英文名称长度超出256个字符',
        'name.regex'            => '名称只能包含英文或中文',
        'name.length'           => '名称长度超出256个字符',
        'status.in'             => '状态非法'
    ];
}
